package com.it.myh;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

/**
 * @Description: // 类说明，在创建类时要填写
 * @ClassName: Ev_0422_02    // 类名，会自动填充
 * @Author: MYH          // 创建者
 * @Date: 2023/4/22 15:24   // 时间
 * @Version: 1.0     // 版本
 */
public class Ev_0422_02 {

    public static void main(String[] args) {
        List<Employee> employees = Employee.getEmployees();
        Stream<Employee> stream = employees.stream();
        //filter()条件过滤
        stream.filter(employee -> employee.getSalary() > 7000).forEach(System.out::println);
        //limit分页查询
        employees.stream().limit(3).forEach(System.out::println);
        //skip跳过前n个，返回剩余的数据
        employees.stream().skip(3).forEach(System.out::println);
        System.out.println();
        //distinct去重
        employees.stream().distinct().forEach(System.out::println);
    }
}
class Employee {

    private Integer id;

    private String name;

    private Integer age;

    private Double salary;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }

    public Employee() {
    }

    public Employee(Integer id, String name, Integer age, Double salary) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee employee = (Employee) o;
        return id.equals(employee.id) && name.equals(employee.name) && age.equals(employee.age) && salary.equals(employee.salary);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, age, salary);
    }

    public static List<Employee> getEmployees(){

        List<Employee> list = new ArrayList<>();
        Employee e1 = new Employee(1001, "马化腾", 34, 6000.38);
        Employee e2 = new Employee(1002, "马云", 34, 604504.38);
        Employee e3 = new Employee(1003, "雷军", 34, 606.38);
        Employee e4 = new Employee(1004, "刘强东", 34, 6456.38);
        Employee e5 = new Employee(1005, "马斯克", 34, 648.32);
        Employee e6 = new Employee(1006, "任正非", 34, 60038.5);
        Employee e7 = new Employee(1007, "扎克伯格", 34, 606.38);
        Employee e8 = new Employee(1008, "比尔盖茨", 34, 50.38);
        list.add(e1);
        list.add(e2);
        list.add(e3);
        list.add(e4);
        list.add(e5);
        list.add(e6);
        list.add(e7);
        list.add(e8);
        list.add(e8);
        list.add(e8);
        list.add(e8);
        return list;
    }
}
